<!DOCTYPE html>
<html>

<head>
    <title>导航栏筋斗云效果</title>
    <meta charset="utf-8">
    <script src="animate.js"></script>
    <style type="text/css">
        * {
            padding: 0;
            margin: 0;
        }
        
        body {
            background-color: rgba(0, 0, 0, 0.6);
        }
        
        .box {
            width: 415px;
            height: 42px;
            margin: 200px auto;
            background-color: #fff;
            position: relative;
        }
        
        ul {
            list-style: none;
            position: relative;
        }
        
        li {
            float: left;
            width: 83px;
            height: 42px;
            text-align: center;
            font: 500 15px/42px "微软雅黑";
            cursor: pointer;
        }
        
        span {
            position: absolute;
            left: 0;
            top: 0;
            width: 83px;
            height: 42px;
            background-image: linear-gradient(to right, #03c03c 50%, #51ee5d 100%);
        }
    </style>
    <script>
        window.addEventListener('load', function() {
            var cloud = document.querySelector('.cloud');
            var box = document.querySelector('.box');
            var lis = box.querySelectorAll('li');
            //起始位置
            var current = 0;
            for (var i = 0; i < lis.length; i++) {
                lis[i].addEventListener('mouseenter', function() {
                    animate(cloud, this.offsetLeft);
                });
                lis[i].addEventListener('mouseleave', function() {

                    animate(cloud, current);
                });
                lis[i].addEventListener('click', function() {
                    current = this.offsetLeft;
                });
            }
        })
    </script>
</head>

<body>
    <div class="box">
        <span class="cloud"></span>
        <ul>
            <li>菜单栏1</li>
            <li>菜单栏2</li>
            <li>菜单栏3</li>
            <li>菜单栏4</li>
            <li>菜单栏5</li>
        </ul>
    </div>
    <script>
    </script>
</body>

</html>